<template>
    <course-form :errors="errors" @complete="createCourse"></course-form>
</template>

<script>
    import CourseForm from "./CourseForm";

    export default {
        components: {CourseForm}, data() {
            return {errors: {}}
        }, methods: {
            createCourse(form) {
                axios.post('courses', form).then((response) => {
                    this.errors = {};
                    this.$emit('complete', response.data.data);
                }).catch((error) => {
                    switch (error.response.status) {
                        case 422://表单校验失败
                            this.errors = _.mapValues(error.response.data.errors, (item) => {
                                return item.join(' ');
                            });
                            break;
                    }
                });
            }
        }
    }
</script>

<style scoped>

</style>